package com.codejoys;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/search")
public class SearchServlet extends HttpServlet {
    private int count;

    //初始化(第一次请求servlet的时候被调用)
    @Override
    public void init() throws ServletException {
        System.out.println("初始化，，，");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println(this);//对象

        System.out.println("get请求");

        System.out.println("访问线程：" + Thread.currentThread());

        resp.getWriter().write("hello");

        count++;
    }

//    @Override
//    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        System.out.println("service...");
//        //处理请求
//        super.service(req, resp);
//    }

    @Override
    public void destroy() {
        //servlet被销毁
        System.out.println("被销毁。。。");
    }
}
